package com.itheima.ydd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.ydd.dto.AdvposDto;
import com.itheima.ydd.dto.AdvposPage;
import com.itheima.ydd.entity.Advimg;
import com.itheima.ydd.entity.Advpos;
import com.itheima.ydd.entity.Result;
import com.itheima.ydd.service.AdvimgService;
import com.itheima.ydd.service.AdvposService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author maorf
 * @version 1.0
 */
@RestController()
@RequestMapping("ydd_advimg")
public class AdvimgController {
    @Autowired
    AdvimgService service;

    @GetMapping("rowInfo")
    public ResponseEntity<Result> getRowInfo(@RequestParam String id) {
        Advimg advimg = service.getById(id);
        return ResponseEntity.ok(new Result(0, "", advimg));

    }

    @GetMapping("list")
    public ResponseEntity<Result> getList(@RequestParam String advimgdesc, String advimgpos, Integer page, Integer limit) {
        AdvposPage advposPage = service.getPage(advimgdesc, advimgpos, page, limit);
        return ResponseEntity.ok(new Result(0, "成功", advposPage));

    }

    @PostMapping("update")
    public ResponseEntity<Result> update(@RequestBody Advimg advimg) {
        service.updateById(advimg);
        return ResponseEntity.ok(new Result(0, "成功"));
    }

    @GetMapping("del")
    public ResponseEntity<Result> delete(Integer id) {
        service.removeById(id);
        return ResponseEntity.ok(new Result(0, "成功"));
    }

    @PostMapping("add")
    public ResponseEntity<Result> save(@RequestBody Advimg advimg) {
        service.save(advimg);
        return ResponseEntity.ok(new Result(0, "成功"));
    }
}
